package com.hj.sort;

import java.util.Arrays;

/**
 * @author hj
 * @Date 2022/1/5
 * @Description: 简单选择排序
 */
public class SimpleSelectionSort {

    public void simpleSelectionSort(int[] array) {
        if (null == array) {
            return;
        }
        int index;
        int temp;
        // 做出选择的次数
        for (int i = array.length-1; i >0; i--) {
            index=0;
            for (int j = 1; j <i ; j++) {
               // 选择一个最大的值(记录索引)
               if(array[j]>array[index]){
                   index=j;
               }
            }
            // 将选出的最大值换到一端
            if(array[index]>array[i]){
                temp=array[index];
                array[index]=array[i];
                array[i]=temp;
            }
        }

    }

    public static void main(String[] args) {
        SimpleSelectionSort simpleSelectionSort = new SimpleSelectionSort();
        int[] array = {5, 9, 125, 6, 85, 97, 45, 3, 25, 64, 36, 98, 103, 45, 12, 35};
        simpleSelectionSort.simpleSelectionSort(array);
        System.out.println(Arrays.toString(array));
    }


}
